<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>活动统计管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/base.css">
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
	<div class="col-xs-6">
		<div class="row-space">
			<div class="e-box float-e-margins" style="height: 470px;">
				<div class="e-box-title">
					<h2>党组织积分统计</h2>
				</div>
				<div class="e-box-content">
					<div id="zjtr" style="width: 100%; height: 420px;"></div>
				</div>
			</div>
		</div>
	</div>
	<form:form id="searchForm" modelAttribute="partyStatistic" action="${ctx}/approve/partyStatistic/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input type="hidden" id="orgId" value="${orgId}"/>
		<input type="hidden" id="typeId" value="${typeId}"/>
		<ul class="ul-form">
			<li><label>社区类型：</label>
				<form:select path="typeId" class="input-medium" id="typeIdSelect">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getPartyType()}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>所属支部：</label>
				<form:select path="organizationId" class="input-medium" id="orgIdSelect">
					<form:option value="" label="全部"/>
				</form:select>
			</li>
			<li><label>年度：</label>
				<form:select path="year" class="input-medium" id="yearSelect" style="width:80px">
					<form:options items="${fns:findAssessmentTimeList()}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="query();"/></li>
			<li class="btns"><input id="btnExport" class="btn btn-primary" type="button" value="导出" onclick="exportExcel()"/></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>排名</th>
				<th>所属支部</th>
				<th>年度</th>
				<th>积分</th>
				<shiro:hasPermission name="approve:partyStatistic:view"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="partyStatistic">
			<tr>
				<td style="text-align:center">
					${partyStatistic.numPm}
				</td>
				<td>
					${partyStatistic.organizationName}
				</td>
				<td style="text-align:center">
					${partyStatistic.year}
				</td>
				<td style="text-align:center">
					${partyStatistic.totalScore}
				</td>
				<shiro:hasPermission name="approve:partyStatistic:view">
					<td style="text-align:center">
	    				<a href="${ctx}/approve/partyStatistic/form?id=${partyStatistic.organizationId}&year=${partyStatistic.year}">查看</a>
					</td>
				</shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	<script src="${pageContext.request.contextPath}/static/js/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="${pageContext.request.contextPath}/static/echarts/echarts.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function(){
			var typeId = $("#typeId").val();
			var orgId = $("#orgId").val();
			if(typeId==null || typeId==''){
				queryOrg(null,null);
			}else{
				queryOrg(typeId,orgId);
			}
			findPartyStatisticChart(typeId,orgId);
		});
		
		//查询按钮点击事件
		function query(){
			var typeId = $("#typeIdSelect").find("option:selected").val();
			var organizationId = $("#orgIdSelect").find("option:selected").val();
			$("#searchForm").submit();
			findPartyStatisticChart(typeId,organizationId);
			
		}
		
		//社区类型change事件，加载组织信息
		$("#typeIdSelect").change(function(){
			var typeId = $(this).val();
			queryOrg(typeId,null);
		});
		
		//查询组织信息下拉
		function queryOrg(typeId,orgId){
			$.ajax({
				url:'${ctx}/approve/partyStatistic/findOrganizeNameByTypeId',
				type:"post",
				data:{"typeId":typeId},
				dataType:"json",
				success:function(data){
					$("#orgIdSelect").empty();
					var html = "<option value=''>全部</option>";
					$("#orgIdSelect").append(html);
					for(var i in data){
						var organizationName = data[i].organizationName;
						var organizationId = data[i].organizationId;
						if(orgId==organizationId){
							var html = "<option value='"+organizationId+"' selected>"+organizationName+"</option>";
						}else{
							var html = "<option value='"+organizationId+"'>"+organizationName+"</option>";
						}
						$("#orgIdSelect").append(html);
					}
				}
			});
		}
	
		var options = {
		  	title : {
		        text: '党组织积分排行(前10名)'
		    },
			legend : {
				show : false,
				data:['党组织积分']
			},
			xAxis : {
				axisLabel : {
					textStyle : {
						fontSize : 12
					},
					rotate :10
				},
				data : []
			},
			yAxis : {
				name : '积分',
				axisLabel : {
					textStyle : {
						fontSize : 10
					},
					formatter : function(value, index) {
						return value;
					}
				}
			},
			series : [ {
				name : '组织名称',
				type : 'bar',
				barMinHeight : 10,
				label : {
					normal : {
						show : true,
						position : 'top',
						textStyle : {
							fontWeight : 'bold',
							fontSize : 10
						}
					}
				},
				itemStyle : {
					normal : {
						color : function(params) {
							var colorList = [ '#cc3333', '#146ddc', '#f99d41',
								'#67b320', '#cc3333', '#146ddc', '#f99d41','#EFE42A','#EE9201','#B74AE5' ];
							return colorList[params.dataIndex];
						},
						opacity : 0.8
					}
				},
				data : []
			} ]
		};
		
		
		//查询前10名党组织积分柱状图
		function findPartyStatisticChart(typeId,orgId){
			var year = $("#yearSelect").find("option:selected").val();
			$.ajax({
				url:'${ctx}/approve/partyStatistic/findPartyPmList',
				type:"post",
				data:{
					"typeId":typeId,
					"organizationId":orgId,
					"year":year
				},
				dataType:"json",
				success:function(data){
					var orgName = [];
					var orgScore = [];
					for(var i in data){
						orgName.push(data[i].organizationName); 
						orgScore.push(data[i].totalScore);
					}
					options.series[0].data = orgScore;
					options.xAxis.data = orgName;
					var zjtrChart = echarts.init(document.getElementById('zjtr'));
				    zjtrChart.setOption(options);
				}
			});
		}
		
		//导出excel
		function exportExcel(){
			var year = $("#yearSelect").find("option:selected").val();
			var typeId = $("#typeIdSelect").find("option:selected").val();
			var organizationId = $("#orgIdSelect").find("option:selected").val();
			document.location.href = "${ctx}/approve/partyStatistic/exportExcel?typeId="+typeId+"&organizationId="+organizationId+"&year="+year;
		}
		
	</script>
</body>
</html>